<template>
	<view>
		<view class="tip-box">
			<view class="tip-item timer">
				<view class="imgbox">
					<image src="/static/images/timer.png"></image>
				</view>
				<view class="text">
					签到时间：<text class="time">{{nowTimeOnlyMin|formatTimeOnlyMin}}</text>
				</view>
			</view>
			<view class="tip-item address">
				<view class="imgbox">
					<image src="/static/images/address.png"></image>
				</view>
				<view class="text">
					签到地址：<text class="time">{{signaddress}}</text>
				</view>
			</view>
			
			
		</view>
		<view class="line-height">
			
		</view>
		
		<view class="photobox">
			<view class="textarea">
				<textarea class="textaretext" placeholder-class="textareaPlace" value="" v-model="remark" placeholder="请填写签到备注" />
			</view>
			<view class="photobox-content">
				<view class="img-box">
					<image class="image" @click="myUpload" :src="url?url:'/static/images/photo_upload.png'"></image>
					<!-- <imgae class="image" @upload="myUpload" src="/static/images/photo_upload.png" ></imgae> -->
				</view>
				<view class="text">
					请拍摄门头照片
				</view>
			</view>
			
		</view>
		
		<view class="tijiao-box" @click="signIn();">
			提交
		</view>
	</view>
</template>

<script>
	import avatar from "../../components/yq-avatar/yq-avatar.vue";
	const util = require("../../utils/util.js");
	//获取应用实例
	const api = require("../../config/api.js");
	export default {
		data() {
			 return {
				 
				url:'',
				signInfor:'',
				remark:'',
				signaddress:'',
				nowTimeOnlyMin:''
			}
		},
		components: {
		            avatar
		},
		filters: {
		  capitalize: function (value) {
		    if (!value) return ''
		    value = value.toString()
		    return value.charAt(0).toUpperCase() + value.slice(1)
		  },
		  
		  formatTimeMin:function (a) {
			 if (!a) return '- - -'
		  	var myDate = new Date(parseInt(a) );
		  	var datestr = "";
		  	datestr = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
		  	datestr =  datestr + "-"+ ((myDate.getMonth() + 1) < 10 ? "0" + (myDate.getMonth() + 1) : (myDate.getMonth() + 1)); //获取当前月份(0-11,0代表1月
		  	datestr = datestr + "-" + (myDate.getDate() < 10 ? "0" + myDate.getDate() : myDate.getDate()); //获取当前日(1-31)
		  	datestr = datestr + " " + (myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours()); //获取当前时
		  	datestr = datestr + ":" + (myDate.getMinutes() < 10 ? "0" + myDate.getMinutes() : myDate.getMinutes()); //获取当前分
		  	return datestr;
		  },
		  formatTimeOnlyMin:function (a) {
		  			 if (!a) return '- - -'
		  	var myDate = new Date(parseInt(a) );
		  	var datestr = "";
		  	// datestr = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
		  	// datestr =  datestr + "-"+ ((myDate.getMonth() + 1) < 10 ? "0" + (myDate.getMonth() + 1) : (myDate.getMonth() + 1)); //获取当前月份(0-11,0代表1月
		  	// datestr = datestr + "-" + (myDate.getDate() < 10 ? "0" + myDate.getDate() : myDate.getDate()); //获取当前日(1-31)
		  	datestr =  (myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours()); //获取当前时
		  	datestr = datestr + ":" + (myDate.getMinutes() < 10 ? "0" + myDate.getMinutes() : myDate.getMinutes()); //获取当前分
		  	return datestr;
		  }
		},
		onLoad(){
			var _that = this;
			
			_that.initSignInfor();
			_that.getNowTime();
			var timer= 	setInterval(function(res){
					// 获取当前的系统时间
					_that.getNowTime();
				},60000);
			uni.setStorageSync('isGetShopInforStorage',false);
		},
		methods: {
			getNowTime(){
				var timestamp=new Date().getTime();
				this.nowTime = timestamp;
				this.nowTimeOnlyMin= timestamp;
				console.log(timestamp);
			},
			myUpload() {
				uni.chooseImage({
				    count: 1, //默认9,
					sourceType:['camera'],
				    success:(res)=>{
						console.log(res)
						// console.log(JSON.stringify(res.tempFilePaths));
						// this.onAccountImage=res.tempFilePaths[0]
						
						uni.showLoading({
						  title: '上传中',
						})
						uni.uploadFile({
							url: api.ImageUpload,
							filePath: res.tempFilePaths[0],
							name: "file",
							success:(res)=>{
								console.log(res)
								this.url=JSON.parse(res.data).data
								console.log(this.url)
								 uni.hideLoading();
							}
						  })
						
						
					}
				});
			},
			initSignInfor(){
				var _that = this;
				var signInfor =	uni.getStorageSync('signInfor',signInfor);
				var signaddress=	uni.getStorageSync('signaddress',signaddress);
				_that.signaddress = signaddress;
			
				_that.signInfor = signInfor; 
				console.log('signInfor',signInfor);
				console.log('signaddress',signaddress);
				
			},
			signIn:function(){
				var that = this;
				// 如果获取地址失败就不让签到、
				if(!that.url){
					uni.showToast({
						title:'请拍摄门头照片!',
						icon:'none'
					})
					return false;
				}
				
				
				var data = that.signInfor;
				data.remark = that.remark;
				data.img = that.url;
				util.request(api.signIn, data, "POST").then(res => {
					if(res.error==0){
						uni.showToast({
							title:'签到成功!',
							icon:'none'
						});
						uni.setStorageSync('isGetShopInforStorage',false);
						setTimeout(function(res){
							uni.navigateBack({  //uni.navigateTo跳转的返回，默认1为返回上一级
											delta: 1
							});
						},1000)
						
					}
					
				})
			}
		

		}
	}
</script>

<style>
	@import url("./signinDetail.css");
</style>
